package com.lijiajian.config;

import com.lijiajian.exceptions.NoLoginException;
import com.lijiajian.interceptor.NoLoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.annotation.Resource;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Resource
    private NoLoginInterceptor noLoginInterceptor;
    @Bean("noLoginInterceptor")
    public NoLoginInterceptor getNoLoginInterceptor() {
        return new NoLoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(noLoginInterceptor).addPathPatterns("/**").
                    excludePathPatterns("/css/**","/images/**","/js/**","/lib/**","/index","/user/login");
    }
}
